#include <bits/stdc++.h>

using namespace std;

const int N = 1010;

int a[N], b[N];
int n, m;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; i++)
        cin >> b[i];

    int res = 2e9;
    for (int i = 0; i + n <= m; i++)
    {
        int dif = 0;
        for (int j = 1; j <= n; j++) {
            dif += (a[j] - b[j+i]) * (a[j] - b[j+i]);
        }
        res = min(res, dif);
    }
    cout << res << endl;
    return 0;
}